package edu.xidian.bdilab.jrbigdata.service.bank.login.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.xidian.bdilab.jrbigdata.controller.bank.BankCode;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.domain.BankUser;
import edu.xidian.bdilab.jrbigdata.mapper.BankUserMapper;
import edu.xidian.bdilab.jrbigdata.service.bank.login.bankuserloginservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class BankLoginserviceimpl implements bankuserloginservice {
    @Autowired
    BankUserMapper bankUserMapper;

    @Override
   public ResponseResult responsResult(String name, String password)
   {
       QueryWrapper<BankUser> userWrapper = new QueryWrapper<>();
       //UpdateWrapper<Enterpriseuser>updateWrapper=new UpdateWrapper<>();

       userWrapper.eq("user_name",name);

      BankUser bankUser= bankUserMapper.selectOne(userWrapper);

      if(bankUser==null)
      {
          ResponseResult responseResult = new ResponseResult();
          responseResult.setCode(BankCode.USERNAME_NULL.getCode());
          responseResult.setMessage(BankCode.USERNAME_NULL.getMessage());
          responseResult.setSuccess(false);
          return responseResult;
      }


      else{
          if(bankUser.getPassword().equals(password))
          {
              ResponseResult responseResult = new ResponseResult();
              //Map<String, Object> data = new HashMap<>();
              //data.put("user_name",bankUser.getUserName());
              //responseResult.setData(data);
              responseResult.setCode(BankCode.LOGINSUCCESS.getCode());
              responseResult.setMessage(BankCode.LOGINSUCCESS.getMessage());
              responseResult.setSuccess(true);
              return responseResult;
          }

          {
              ResponseResult responseResult = new ResponseResult();
              responseResult.setCode(BankCode.PASSWORD_WRONG.getCode());
              responseResult.setMessage(BankCode.PASSWORD_WRONG.getMessage());
              responseResult.setSuccess(false);
              return responseResult;
          }
      }

   }

}
